using UnityEngine;
using System.Collections;

[System.Serializable]
public class AchievementNPC : AchievementItem {

	public int NUM_npc;
	private string TAG = "NPC Achievement";
	public int[] npcs;
	
	public string completed_key = "NPCAchievement_Completed";
	public string save_key = "NPCAchievement";
		
	
	public void Setup()
	{
		this.npcs = new int[NUM_npc];
		
		int tmpCompleted = PlayerPrefs.GetInt(this.completed_key);
		if(tmpCompleted == 1)
		{
			SetCompleted();
		}
		
		Load();
		
	}
	public void SetNpc (int npc_id)
	{
		this.npcs[npc_id] = 1;
		Save(this.npcs);
	}
	
	public bool Teste_UnlockAchieve()
	{
		
		foreach(int i in npcs)
		{
			if(i != 1)
			{
				return false;
			}
		}
		
		SetCompleted();
		return true;
	}
	
	public void Save(int[] npcs)
	{
		for (int i = 0; i < this.NUM_npc; i++) {
		
			PlayerPrefs.SetInt(this.save_key + i.ToString(), this.npcs[i]);
		}
		Debug.Log(TAG + ": SAVE SUCCESS");
	}
	
	public void Load()
	{

		for (int i = 0; i < this.NUM_npc; i++) {
			
			this.npcs[i] = PlayerPrefs.GetInt(this.save_key + i.ToString());
		}
		Debug.Log(TAG + ": LOAD SUCCESS");
	}

	public void SetCompleted()
	{
		this.completed = true;
		PlayerPrefs.SetInt(this.completed_key, 1);
		AchieveStorage.getInstance.getByName(this.name).SetCompleted();
		Debug.Log(TAG + ": Set Completed");	
	}
}
